package com.evergrande.mybatis.controller;

import com.evergrande.mybatis.model.NavTreeDto;
import com.evergrande.mybatis.pojo.EasyUITree;
import com.evergrande.mybatis.service.NavTreeDtoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by cuican on 2016-8-17.
 */
@RequestMapping("/rest/sys")
@Controller
public class SystemController {

    private Logger logger = LoggerFactory.getLogger(SystemController.class);

    @Autowired
    private NavTreeDtoService navTreeDtoService;

    /**
     * 获取主页左侧导航栏的Tree node
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/nav/tree", method = RequestMethod.POST)
    public ResponseEntity<List<NavTreeDto>> getNavTreeByPid(@RequestParam(value = "id",defaultValue = "0") Integer id) {
        try {
            logger.info("获取属于该父id的所有节点的list集合。。。");
            List<NavTreeDto> list = this.navTreeDtoService.selectNavTreeListByPid(id);
            if (null == list) {
                //404
                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
            }
            //200
            return ResponseEntity.ok(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //500
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
